
package Model;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

public class Mysql {
    
    public static MysqlDataSource dataSource = new MysqlDataSource();
    public static Connection connection = null;
    public static Statement st;
    public static ResultSet resultSet;
    public static ResultSetMetaData metaData;
    
   // private File file;
    
    
    
    
    public Mysql (){
         try {
            
            dataSource.setServerName("localhost");
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("pollolandia");
            // me conecto 

            connection = (Connection) dataSource.getConnection();
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error en Conexion en Base de Datos \n "+ex);
            System.exit(0);
        }
    }
    
    
    
   public static void Query (String consulta){
        try {
            
            st = (Statement) connection.createStatement();
         
            st.executeUpdate(consulta);
            
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error al ingresar datos "+ex);
        }
  } 
    
   /* 
    * Esto es en un caso profesional jajaja. 
    * 
    * public Mysql(String [] datos, File file){ // contructor 
        this.file = file;
        try {
            
            dataSource.setServerName(datos[0]);
            dataSource.setUser(datos[1]);
            dataSource.setPassword(datos[2]);
            dataSource.setDatabaseName(datos[3]);
            // me conecto 

            connection = (Connection) dataSource.getConnection();
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error en Conexion en Base de Datos \n "+ex);
            file.delete();  // borro el archivo. 
            System.exit(0);
        }
        
        Process p=null;
        Runtime r=Runtime.getRuntime();
        // leo el backup.sql 
        try
        {
           // p=r.exec("cmd /c mysql --password="+datos[2]+" --user="+datos[1]+" "+datos[3]+" < backup.sql");

        }
        catch(Exception e)
        {
        JOptionPane.showMessageDialog(null, "Error al cargar backup");
        }
        * 
        
    }
    * 
    */

    
    
    
}
